home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
telecomm
/
wterm.arc
/
WTERMF.C
< prev
next >
Wrap
C/C++ Source or Header
|
1985-11-20
|
24KB
|
787 lines
/*
* WTERMF - Window Terminal, 'full' version
*
* Matt Kimmel, 1987
*
* This program implements a terminal program inside a window as a desk
* accessory. See the header in the 'stripped' version for programming
* notes.
*
* This version is larger and slower but contains many features - three
* font sizes, RS232 buffer sizing, a cursor, setting of RS232 parameters,
* and saving of configuration. This version requires a resource file,
* WTERMF.C.
*
*/
#include <stdio.h>
#include <gemdefs.h>
#include <osbind.h>
#include <obdefs.h>
#include <string.h>
#include "wtermf.h" /* Resource defs */
/* Defines for window gadgets */
#define NAME 0x0001
#define CLOSE 0x0002
#define FULL 0x0004
#define MOVE 0x0008
#define SIZE 0x0020
/* Macros to turn mouse pointer on and off */
#define MOUSE_ON graf_mouse(257,&j)
#define MOUSE_OFF graf_mouse(256,&j)
/* Structure for iorec() */
typedef struct {
char *ibuf;
int ibufsiz;
int ibufhd;
int ibuftl;
int ibuflow;
int ibufhi;
} IORECORD;
/* VDI variables - why aren't these in a header file? */
int contrl[12], intin[128],ptsin[128],intout[128],ptsout[128];
int w_handle, handle, workin[11], workout[57];
int x,y,w,h; /* Current coordinates of window */
int j;
int nx, ny; /* coordinates of next character to be output */
int tx, ty, tw, th; /* Work area of window */
int hsize, vsize; /* Horizontal and vertical size of characters */
int apid, menuid;
OBJECT *mainmenu, *setrs, *setfont, *rsize;
int baud, ucr, flow, cursor, point, buffer_size; /* Various parameters */
char *rb; /* Pointer to our RS232 buffer */
char strsiz[10];
char aboutstr[] = "[1][Window Term 1.0|Full Version|by Matt Kimmel, 1987][OK]";
main()
{
int j;
int msg[8];
FILE *conf;
int dx,dy,dw,dh; /* Desktop work area */
apid = appl_init();
if (!rsrc_load("WTERMF.RSC"))
for(;;)
evnt_mesag(msg); /* If we can't open the resource file, we'll
just sit here and release the system to
the time slicer */
rsrc_gaddr(0,MENU,&mainmenu);
rsrc_gaddr(0,RS232,&setrs);
rsrc_gaddr(0,FONT,&setfont);
rsrc_gaddr(0,BUFSET,&rsize);
((TEDINFO *)rsize[BSIZ].ob_spec)->te_ptext = strsiz;
if ((conf = fopen("\WTERMF.INF","r")) == NULL) {
/* If we can't open the config file, set up the defaults */
baud = 7; /* 1200 baud */
ucr = 136; /* 8,N,1 */
flow = 0; /* no flow control */
cursor = 1; /* cursor on */
point = ((Getrez() == 2)?(10):(9)); /* normal font for this resolution */
buffer_size = 8192; /* 8K RS232 buffer */
/* default window coordinates */
x=50;
y=50;
w=200;
h=100;
}
else {
/* Get parameters from the config file */
fscanf(conf,"%d",&baud);
fscanf(conf,"%d",&ucr);
fscanf(conf,"%d",&flow);
fscanf(conf,"%d",&cursor);
fscanf(conf,"%d",&point);
fscanf(conf,"%d",&buffer_size);
fscanf(conf,"%d",&x);
fscanf(conf,"%d",&y);
fscanf(conf,"%d",&w);
fscanf(conf,"%d",&h);
fclose(conf);
}
wind_get(0,WF_WORKXYWH,&dx,&dy,&dw,&dh); /* Get work area of desktop */
/* Fix window coordinates if necessary to fit inside desktop */
if ((x < dx) || (x > (dx + dw))) x=dx;
if ((y < dy) || (y > (dy+dh))) y=dy;
if ((x + w) > (dx + dw)) w=((dx + dw) - x) - 8;
if ((y + h) > (dy + dh)) h=((dy + dh) - x);
/* Align window to be byte-aligned in screen RAM */
align8(&x,&y,&w,&h);
init_buttons(); /* Set up buttons in dialog boxes */
if ((point == 10) && (Getrez() != 2)) point = 9; /* Fix font for color */
Rsconf(baud,flow,ucr,-1,-1,-1);
menuid = menu_register(apid," Window Terminal");
handle = graf_handle(&j,&j,&j,&j);
for(j=0;j++<=9;workin[j]=1);
workin[10] = 2;
v_opnvwk(workin,&handle,workout);
vst_alignment(handle,0,5,&j,&j);
vst_point(handle,point,&j,&j,&hsize,&vsize);
vst_color(handle,1);
vsl_color(handle,1);
vswr_mode(handle,1);
/* Allocate new RS232 buffer. calloc() is used because it zeroes the
memory it allocates */
rb = calloc(buffer_size,sizeof(char));
/* If we can't allocate the memory, hang */
if (rb == NULL)
for (;;)
evnt_mesag(msg);
set_rsbuf();
for (;;) {
evnt_mesag(msg); /* Wait around to be selected */
if (msg[0] == AC_OPEN)
acc();
}
}
/*
* This is the main accessory - it handles messages and i/o.
*/
acc()
{
int msg[8], d, which;
int i;
int a, j;
int desel = 0; /* Is the window deselected? */
int dx,dy,dw,dh;
int stopped = 0; /* Has the window been stopped with ALT-S? */
long l;
int p[4];
if (init_window() == 0) return; /*If we can't allocate a window, forget it*/
align8(&x,&y,&w,&h);
graf_growbox(24,0,56,16,x,y,w,h);
wind_open(w_handle,x,y,w,h); /* Open our window */
wind_get(w_handle,WF_WORKXYWH,&tx,&ty,&tw,&th); /* Get its work area */
clr(); /* clear it */
Cauxout(17); /* Send a CTRL-Q, just in case */
for(;;) {
/* Release time to the time slicer, but come back every (theoretically)
0 milliseconds. Also wait for messages. */
which = evnt_multi(MU_MESAG|MU_TIMER,0,0,0,0,0,0,0,0,0,0,0,0,0,
msg,0,0,&d,&d,&d,&d,&d,&d);
/* See if our window is still on top */
wind_get(w_handle,WF_TOP,&a,&j,&j,&j);
if ((a != w_handle) && (desel == 0)) { /* Window has been deselected */
if (stopped != 1) Cauxout(19); /* Send a CTRL-S if the window isn't
stopped */
desel = 1;
}
else
if ((a == w_handle) && (desel == 1)) { /* Window has been selected */
if (stopped != 1) Cauxout(17); /* Send a CTRL-Q, if window isn't
stopped */
desel = 0;
}
/* If there are no messages and our window is on top, do some i/o */
if ((which & MU_TIMER) && (a == w_handle)) {
/* If there's a character waiting at the keyboard, get it */
if (Bconstat(2)) {
l = Bconin(2);
if (l == 2031616L) /* Is it ALT-S? */
if (stopped == 0) { /* Yes, toggle stopped window */
Cauxout(19);
stopped = 1;
}
else {
Cauxout(17);
stopped = 0;
}
Cauxout((int)l); /* Output the character to RS232. If it was ALT-S,
a 0 will be output */
}
/* If there's a character waiting at the RS232 port, and the
window is not stopped, output it. */
if (Cauxis() && (stopped == 0)) {
i = Cauxin();
MOUSE_OFF; /* turn off mouse */
if (cursor) { /* erase cursor */
p[0] = (nx + (hsize / 2));
p[1] = (ny - 1);
p[2] = p[0];
p[3] = ((ny + vsize) + 1);
vswr_mode(handle,3);
v_pline(handle,2,p);
vswr_mode(handle,1);
}
outchar(i); /* output the character */
if (cursor) { /* draw the cursor */
p[0] = (nx + (hsize / 2));
p[1] = (ny - 1);
p[2] = p[0];
p[3] = ((ny + vsize) + 1);
vswr_mode(handle,3);
v_pline(handle,2,p);
vswr_mode(handle,1);
}
MOUSE_ON; /* turn on the mouse */
}
}
if (which & MU_MESAG) {
switch(msg[0]) {
case WM_REDRAW : redraw(); /* redraw window and reset character */
nx=tx; /* coordinates */
ny=ty;
break;
case WM_NEWTOP : /* put appropriate window on top */
case WM_TOPPED : wind_set(w_handle,WF_TOP,msg[3],0,0,0);
clr();
break;
case AC_OPEN : do_menu(); /* Let the user select a command */
break;
case AC_CLOSE : return; /* Our window has been closed and deleted */
break; /* for us. */
case WM_CLOSED : wind_close(w_handle); /*